package com.xqb.modules.controller.order;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.dto.AddOrdRefundApplyDto;
import com.xqb.modules.domain.dto.OrdRefundApplyDto;
import com.xqb.modules.domain.po.OrdRefundApply;
import com.xqb.modules.domain.vo.OrdRefundApplyVo;
import com.xqb.modules.service.IOrdRefundApplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 退款申请Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/order/refundApply")
@Slf4j
public class OrdRefundApplyController extends BaseController
{
    @Autowired
    private IOrdRefundApplyService ordRefundApplyService;

    /**
     * 查询退款申请列表
     */
    @PreAuthorize("@ss.hasPermi('order:refund_apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdRefundApply ordRefundApply)
    {
        startPage();
        List<OrdRefundApply> list = ordRefundApplyService.selectOrdRefundApplyList(ordRefundApply);
        return getDataTable(list);
    }

    /**
     * 导出退款申请列表
     */
    @PreAuthorize("@ss.hasPermi('order:refund_apply:export')")
    @Log(title = "退款申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrdRefundApply ordRefundApply)
    {
        List<OrdRefundApply> list = ordRefundApplyService.selectOrdRefundApplyList(ordRefundApply);
        ExcelUtil<OrdRefundApply> util = new ExcelUtil<OrdRefundApply>(OrdRefundApply.class);
        util.exportExcel(response, list, "退款申请数据");
    }

    /**
     * 获取退款申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:refund_apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ordRefundApplyService.selectOrdRefundApplyById(id));
    }

    /**
     * 新增退款申请
     */
    @PreAuthorize("@ss.hasPermi('order:refund_apply:add')")
    @Log(title = "退款申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddOrdRefundApplyDto addOrdRefundApplyDto)
    {
        return toAjax(ordRefundApplyService.insertOrdRefundApply(addOrdRefundApplyDto));
    }

    /**
     * 修改退款申请
     */
    @PreAuthorize("@ss.hasPermi('order:refund_apply:edit')")
    @Log(title = "退款申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdRefundApply ordRefundApply)
    {
        return toAjax(ordRefundApplyService.updateOrdRefundApply(ordRefundApply));
    }

    /**
     * 处理退款订单
     */
    @PreAuthorize("@ss.hasPermi('order:refund_apply:edit')")
    @PutMapping("/handle")
    public AjaxResult handle(@RequestBody OrdRefundApplyDto ordRefundApplyDto) {
        return toAjax(ordRefundApplyService.handleOrdRefundApply(ordRefundApplyDto));
    }

    /**
     * 删除退款申请
     */
    @PreAuthorize("@ss.hasPermi('order:refund_apply:remove')")
    @Log(title = "退款申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ordRefundApplyService.deleteOrdRefundApplyByIds(ids));
    }
    /**
     * 查询机构退款申请列表
     */
    @PreAuthorize("@ss.hasPermi('order:refund_apply:list')")
    @GetMapping("/institution/list")
    public TableDataInfo institutionList(OrdRefundApplyDto ordRefundApply)
    {
        startPage();
        startOrderBy();
        List<OrdRefundApplyVo> list = ordRefundApplyService.selectOrdRefundApplyInstitutionList(ordRefundApply);
        return getDataTable(list);
    }
    @PutMapping("/approve/{id}")
    public AjaxResult approve(@PathVariable Long id) {
        return toAjax(ordRefundApplyService.approveOrdRefundApply(id));
    }

    @PutMapping("/reject/{id}")
    public AjaxResult reject(@PathVariable Long id) {
        return toAjax(ordRefundApplyService.rejectOrdRefundApply(id));
    }
}
